package com.home.duy.code.Model;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Vector;

import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;

import com.home.Entity.TaiKhoan;
import com.home.duy.GUI.ParentFrame;
import com.home.duy.GUI.ThongTinTK;
import com.home.duy.code.DAO.TaiKhoanDAO;

public class TTTKTableModel extends AbstractTableModel implements
		TableModelListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String[] column = { "Tên Nhân Viên", "Tên Tài Khoản", "Ghi Chú",
			"Sử Dụng", "Online" };

	public TTTKTableModel(JTable table, ParentFrame parent, JInternalFrame frame) {

	}

	public TTTKTableModel() {
	}

	@Override
	public int getColumnCount() {
		return column.length;
	}

	@Override
	public int getRowCount() {
		return getData().size();
	}

	@SuppressWarnings("rawtypes")
	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		if (getData().size() > 0)
			return ((Vector) getData().get(rowIndex)).get(columnIndex);
		else
			return "";
	}

	@Override
	public String getColumnName(int column) {
		// TODO Auto-generated method stub
		return this.column[column];
	}

	@Override
	public Class<?> getColumnClass(int arg0) {
		return getValueAt(0, arg0).getClass();
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private Vector getData() {
		Vector<Object> v = new Vector<Object>();
		TaiKhoanDAO tkDao = new TaiKhoanDAO();
		List<TaiKhoan> taiKhoans = tkDao.findAll(TaiKhoan.class);
		for (TaiKhoan tk : taiKhoans) {
			if (!tk.isLoai()) {
				Vector<Object> column = new Vector<Object>();
				column.add(tk.getNhanVien().getTen());
				column.add(tk.getTen());
				column.add(tk.getGhiChu());
				column.add(tk.isTinhTrang());
				column.add(tk.isTrangThai());
				column.add(tk.getMaSo());
				v.add(column);
			}
		}
		return v;
	}

	@Override
	public void tableChanged(TableModelEvent arg0) {
		// TODO Auto-generated method stub

	}

}
